<!--调试科研创新管理-论文查询-->
<template>
  <PageTemplate>
    <div class="thesis-list" slot="content">
      <el-form
        inline
        :model="query"
        ref="query"
        label-position="right"
        label-width="110px"
        class="search-collapse-pro-form"
      >
        <SearchCollapsePro>
          <div slot="title" class="search-collapse-pro-title">
            <el-form-item label-width="0px">
              <el-input v-model="query.paperName" placeholder="论文名称">
                <el-button slot="append" icon="el-icon-search" @click="queryDataTableLike"></el-button>
              </el-input>
            </el-form-item>
          </div>
          <div slot="collapse">
            <!-- 高级搜索具体内容 -->
            <el-row>
              <el-col :span='8'>
                <el-form-item label="专业部分" prop="professional">
                  <el-select v-model="query.professional"  placeholder="请选择" >
                    <el-option
                      v-for="item in professionalMap"
                      :key="item.dictText"
                      :label="item.dictText"
                      :value="item.dictKey+''">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span='8'>
                <el-form-item label="论文中文名称" prop="projectName">
                  <el-input v-model="query.projectName" ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span='8'>
                <el-form-item label="第一作者" prop="firstAuthor">
                  <el-input v-model="query.firstAuthor" ></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span='8'>
                <el-form-item label="是否刊出" prop="isPublish">
                  <el-select v-model="query.isPublish"  placeholder="请选择" >
                    <el-option label="全部" value=""></el-option>
                    <el-option label="是" value="1"></el-option>
                    <el-option label="否" value="0"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span='8'>
                <el-form-item label="期刊名称" prop="periodicalName">
                  <el-input v-model="query.periodicalName" ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span='8'>
                <el-form-item label="索引类别" prop="indexType">
                  <el-select
                    v-model="query.indexType"
                    placeholder="请选择">
                    <el-option
                      v-for="item in indexTypeMap"
                      :key="item.dictText"
                      :label="item.dictText"
                      :value="item.dictKey+''">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span='8'>
                <el-form-item label="发表日期">
                  <el-date-picker
                    v-model="query.publishDate"
                    type="date"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span='8'>
                <el-form-item label="其它作者">
                  <el-input v-model="query.otherAuthor"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 查询和重置按钮-->
            <el-row :gutter="10">
              <div class="btn-group-search">
                <el-col :span="2">&nbsp;</el-col>
                <el-col :span="6">
                  <el-button
                    type="primary"
                    class="btn-default"
                    @click="getAllDataTable"
                    size="small"
                  >{{$t('cm.query')}}</el-button>
                  <el-button
                    class="btn-second"
                    @click="queryReset('query')"
                    style="margin:0;"
                    size="small"
                  >{{$t('cm.reset')}}</el-button>
                </el-col>
              </div>
            </el-row>
          </div>
        </SearchCollapsePro>
      </el-form>
      <el-row class="row-empty-20"></el-row>
      <PageTableCollapse :collapseStatus="true">
        <el-row slot="title">
          <el-col>
            <div>
              <el-button v-if="showBtn && isSys ==='true'" icon="el-icon-edit" type="primary" @click="addHandle">
                新增
              </el-button>
              <el-button icon="el-icon-download" type="primary" @click="exportHandle">
                导出
              </el-button>
            </div>
          </el-col>
        </el-row>
        <el-table
          class="table"
          border
          ref="multipleTable"
          :data="tables"
          tooltip-effect="dark"
          style="width: 100%"
          :show-overflow-tooltip="true"
          @selection-change="handleSelectionChange"
          :header-cell-style="{background:tableHeaderBGC}"
        >
          <el-table-column align="center" type="selection" width="60"></el-table-column>
          <el-table-column type="index" :index="indexMethod" :label="$t('cm.no')" align="center" width="60" fixed></el-table-column>
          <el-table-column prop="paperName" label="论文名称" align="center"></el-table-column>
          <el-table-column prop="firstAuthor" label="第一作者" align="center"></el-table-column>
          <el-table-column prop="otherAuthor" label="其他作者" align="center"></el-table-column>
          <el-table-column prop="keyword" label="关键词" align="center"></el-table-column>
          <el-table-column prop="professionalLabel" label="专业领域" align="center"></el-table-column>
          <el-table-column
            prop="isPublish" label="是否刊出" align="center"
            :formatter="(row)=>{
              let result = '';
              switch (row.isPublish-0) {
                case 0:
                  result = '否';
                  break;
                case 1:
                  result = '是';
                  break;
              }
              return result;
            }"></el-table-column>
          <el-table-column prop="periodicalName" label="期刊名称" align="center"></el-table-column>
          <el-table-column prop="indexTypeLabel" label="索引类别" align="center"></el-table-column>
          <el-table-column :label="$t('cm.operate')" prop="statussss" fixed="right" align="center" width="140"  v-if="isSys ==='false'">
            <template slot-scope="scope">
              <ListBtnSys :options="sysbtns" :is-sys='isSys' :row-data="scope.row" @triggerListBtn="handleListBtn"></ListBtnSys>
            </template>
          </el-table-column>
          <el-table-column :label="$t('cm.operate')" prop="statussss" fixed="right" align="center" width="140"  v-if="isSys ==='true'">
            <template slot-scope="scope">
              <ListBtn :options="btns" :row-data="scope.row" @triggerListBtn="handleListBtn"></ListBtn>
            </template>
          </el-table-column>
        </el-table>
        <div class="block pager-customer">
          <el-pagination
            background
            layout="total,prev,pager, next,jumper"
            :current-page.sync="pagingCurrentPageNum"
            :page-sizes="pagingPageSizes"
            :page-size="pagingPageSize"
            :total="pagingTotal"
            @size-change="pagingHandleSizeChange"
            @current-change="pagingHandleCurrentChange"
          >
          </el-pagination>
        </div>
      </PageTableCollapse>
    </div>
  </PageTemplate>
</template>

<script>
  import { mapState, mapActions } from 'vuex'
  import PageTemplate from '@/components/common/PageTemplate'
  import PageTableCollapse from '@/components/common/PageTableCollapse'
  import SearchCollapsePro from '@/components/common/SearchCollapsePro'
  import ListBtn from '@/components/btn/ListBtn'
  import { ALERT } from '@/utils/responseHandle'
  import * as Constant from '@/utils/constant'
  import {COMMON} from '@/utils/commonUtil'
  import Pagination from '@/mixins/Pagination'
  import HasBtn from '@/mixins/HasBtn'
  import api_sri from '@/api/api_sri'
  import sys_manage from '@/api/sys_manage'
  import {dateFtt} from '@/utils/datetime'
  import ListBtnSys from '@/components/btn/ListBtnSys'
  import { getUserRoles } from '@/api/api.js'
  export default {
    components: {
      PageTemplate,
      PageTableCollapse,
      SearchCollapsePro,
      ListBtn,
      ListBtnSys
    },
    data () {
      return {
        query: {
          paperName: "",
          firstAuthor: null,
          deptId:null,
          isPublish:null,
          periodicalName:null,
          indexType:null,
          publishDate: null,
          otherAuthor: null,
          professional:null
        },
        tables:[],
        btns: [
          {
            value: 'look',
            label: 'cm.look'
          },
          {
            value: 'modify',
            label: 'cm.modify'
          }
        ],
        sysbtns: [
          {
            value: 'look',
            label: 'cm.look',
            isdba: 'true',
          },
          {
            value: 'modify',
            label: 'cm.modify',
            isdba: 'false'
          }
        ],
        isSys: '',
        professionalMap:[],
        indexTypeMap:[],//索引类别字典

      }
    },
    created () {
      //获取全部字典
      this.getAllMap();
      this.getAllDataTable();
      this.getNowUserRole()
    },
    mixins: [Pagination, HasBtn],
    computed: {
      ...mapState({
        tableHeaderBGC: state => state.common.tableHeaderBGC
      })
    },
    methods:{
      //获取全部字典
      getAllMap(){
        //索引类别字典
        this.sysDictLoadByPaging("achievement_index_type",(result)=>{
          this.indexTypeMap = result.data
        })
        this.sysDictLoadByPaging("achievement_professional",(result)=>{
          this.professionalMap = result.data
        })
      },
      //获取角色权限
      getNowUserRole(){
        let _this = this;
        getUserRoles({}).then((result) => {
          if (result.status == "200" && result.data.code == "0") {
            //console.log("==biaozhuan==244===:",result.data.data);
            let dataList = result.data.data
            // sysadmin 系统管理员
            const isAdmin = dataList.some(item => item ==='sysadmin')
            console.log('===isAdmin:',isAdmin)
            if(isAdmin){
              _this.isSys= 'true'
            }else{
              _this.isSys= 'false'
            }
            //console.log("deptNamePath",result.data.data.deptNamePath);
          } else {
            _this.$alert(result.data.msg, _this.$t('cm.tips'));
          }
        }).catch((err) => {
          _this.$alert(err,_this.$t('cm.tips'));
        });
      },
      //获取字典接口
      sysDictLoadByPaging (key,callback) {
        sys_manage.sysDictLoadByPaging({dictGroupKey: key}, result => {
          if (result.code === Constant.RT_SUCCESS) {
            callback(result)
          } else {
            ALERT.error(result.msg)
          }
        })
      },
      handleListBtn({btn,row}){
        if(btn==="look"){//查看
          COMMON.routerTo(Constant.ROUTE_SRI_GAIN_THESIS_LOOK.index, this.$router, { id: row.id })
        }else{//编辑
          COMMON.routerTo(Constant.ROUTE_SRI_GAIN_THESIS_EDIT.index, this.$router, { id: row.id})
        }
      },
      //重置操作
      queryReset (formName) {
        this.$refs[formName].resetFields()
      },
      //新增
      addHandle(){
        COMMON.routerTo(Constant.ROUTE_SRI_GAIN_THESIS_ADD.index, this.$router)
      },
      //导出excel之前,勾选id
      handleSelectionChange(val) {
        this.multipleSelection = val
        this.query.ids = [];
        val.forEach(item => {
          this.query.ids.push(item.id);
        });
      },
      // 导出
      exportHandle () {
        let params = Object.assign({},this.query,{
          pageNum:this.pagingCurrentPageNum,
          pageSize:this.pagingPageSize
        })
        let fileName = `调试科研创新管理_论文管理_论文列表_${dateFtt('yyyy-MM-dd', new Date())}`
        api_sri.sriGainPaperExportExcel(params, response => {
          if (response.code === Constant.RT_SUCCESS) {
            COMMON.downloadLinkByUrl(response.data.webRequestUrl, fileName)
          } else {
            ALERT.alertResp(response)
          }
        })
      },
      queryDataTableLike () {
        this.getAllDataTable();
      },
      getAllDataTable () {
        let publishDateFrom = null
        let publishDateTo = null
        if (this.query.publishDate) {
          publishDateFrom = `${this.query.publishDate} 00:00:00`
          publishDateTo = `${this.query.publishDate} 23:59:59`
        }
        this.queryTableList({
          ...this.query,
          publishDateFrom,
          publishDateTo,
          pageNum: this.pagingCurrentPageNum,
          pageSize: this.pagingPageSize
        })
      },
      //统一与后台操作的方法
      queryTableList (params) {
        //这里的params是对象
        //注意 如果后台json转对象 时间类型好像会抛异常  转到后台 前台用 qs 来转换数据 设置一个全局拦截器 main.js 参考
        let _this = this
        let tables = []
        let totalCount = 0
        api_sri.sriGainPaperList(params, result => {
          if (result.code === Constant.RT_SUCCESS) {
            //表格数据  数组
            tables = result.data.results
            //分页数据
            totalCount = result.data.totalRows
          } else {
            // _this.$t('cm.tips')
            ALERT.error(result.data.msg)
          }
          _this.setPagingTotal(totalCount)
          this.tables = tables
        })
      },
    }
  }

</script>

<style lang="scss">

</style>
